jsx3.require("tibco.admin.enterpriseAssets.EnterpriseAssetsTabInterface");
/*
* Modified by Felix
* Date: 6/13/2007
*/
jsx3.lang.Class.defineClass("tibco.admin.environments.shdReso.ShdReso",
        jsx3.lang.Object,
        [tibco.admin.environments.EnvironmentsInterface, tibco.admin.plugin.PluginContainerInterface],
        function (plugin) {
            plugin.imagesForType = new Object();
            plugin.stringsForType = new Object();

            plugin.instance = null

            plugin.prototype.init = function() {
                this.jsxsuper();
                tibco.admin.Main.loadResource("tibco/admin/environments/shdReso/jss/jss.xml", "tibco.admin", "jss34", "ljss", false);
                tibco.admin.Main.loadResource("tibco/admin/environments/shdReso/jss/xslt.xml", "tibco.admin", "xslt34", "jss", false);
            }

            plugin.prototype.getNamespace = function() {
                return "tibco.admin";
            }

            plugin.prototype.destroyPlugin = function() {
            }

            plugin.getInstance = function(args) {
                if(!this.instance) {
                    this.instance = new tibco.admin.environments.shdReso.ShdReso();
                }
                return this.instance;
            }

            plugin.prototype.setupPlugin = function(obj) {

            }

            plugin.prototype.getImageForType = function(type) {
                var ret = plugin.imagesForType[type];
                if(!ret) {
                    var iter = this.getPluginList().iterator();
                    while(iter.hasNext()) {
                        var item = iter.next();
                        if(item.getType() == type) {
                            ret = "" + item.getImagePath();
                            if(!ret) {
                                ret = tibco.admin.Main.getServer().getDynamicProperty("@addin@Blank Icon Path");
                            }
                            else {
                                plugin.imagesForType[type] = ret;
                            }
                        }
                    }
                }
                if(!ret) {
                    ret = tibco.admin.Main.getServer().getDynamicProperty("@addin@Blank Icon Path");
                }
                return ret;
            }

            plugin.prototype.getDisplayStringForType = function(type) {
                var ret = plugin.stringsForType[type];
                if(!ret) {
                    var iter = this.getPluginList().iterator();
                    while(iter.hasNext()) {
                        var item = iter.next();
                        if(item.getType() == type) {
                            ret = "" + item.getAddText();
                            if(!ret) {
                                ret = type
                            }
                            else {
                                plugin.stringsForType[type] = ret;
                            }
                        }
                    }
                }
                if(!ret) {
                    ret = type;
                }
                return ret;
            }

            plugin.prototype.onAfterGetPlugins = function() {
                this.callgetManagedResourceNodeAssociations();
            }

            plugin.prototype.loadComponent = function(parent) {
                var me = this;
                tibco.admin.Main.loadUIResourceAsync(parent, "tibco.admin", "tibco/admin/environments/shdReso/ui/shdReso.xml", me, me.loadDetails);
            }

            plugin.prototype.getButtonText = function(parent) {
                return tibco.admin.Main.getServer().getDynamicProperty("@@lblSectionTitle_34");
            }

            plugin.prototype.setEnvId = function(id) {
                this.envId = id;
            }

            plugin.prototype.setNodeIds = function(arrIds) {
                if(this.isInEditMode() && !this.isAddMode) {
                    if((arrIds && (arrIds.length == 1) && (arrIds[0] != this.nodeId)) || (this.nodeId && (!arrIds || (arrIds.length != 1)))) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@msgCannotUpdateNodeIdTitle_34"), tibco.admin.Main.getServer().getDynamicProperty("@@msgCannotUpdateNodeIdMessage_34"));
                    }
                    return;
                }

                if(arrIds && ( arrIds.length == 1 )) {
                    this.nodeId = arrIds[ 0 ];
                }
                else {
                    this.nodeId = null;
                }

                if(!this.isAddMode && this.block && this.nodeId) {
                    if(!tibco.admin.enterpriseAssets.shdResDefs.ShdResDefDetails) {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/ShdResDefDetails.js",
                                "tibco.admin");
                    }
                    if(this.getPluginList().size() == 0) {
                        var preLoad = new jsx3.util.List(0);

                        // load bundled shared resource definitions
                        // TODO: add RV, SSL
                        if(!tibco.admin.enterpriseAssets.shdResDefs.HTTP || !tibco.admin.enterpriseAssets.shdResDefs.HTTP.ShdHttpResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/HTTP/ShdHttpResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.HTTP.ShdHttpResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.HTTP.ShdHttpResDefs, preLoad.size());
                        }
                        if(!tibco.admin.enterpriseAssets.shdResDefs.JDBC || !tibco.admin.enterpriseAssets.shdResDefs.JDBC.ShdJdbcResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/JDBC/ShdJdbcResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JDBC.ShdJdbcResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JDBC.ShdJdbcResDefs, preLoad.size());
                        }
                        if(!tibco.admin.enterpriseAssets.shdResDefs.EMS || !tibco.admin.enterpriseAssets.shdResDefs.EMS.ShdEmsResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/EMS/ShdEmsResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.EMS.ShdEmsResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.EMS.ShdEmsResDefs, preLoad.size());
                        }
                        if(!tibco.admin.enterpriseAssets.shdResDefs.JNDI || !tibco.admin.enterpriseAssets.shdResDefs.JNDI.ShdJndiResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/JNDI/ShdJndiResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JNDI.ShdJndiResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JNDI.ShdJndiResDefs, preLoad.size());
                        }
                        if(!tibco.admin.enterpriseAssets.shdResDefs.RV || !tibco.admin.enterpriseAssets.shdResDefs.RV.ShdRVResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/RV/ShdRVResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.RV.ShdRVResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.RV.ShdRVResDefs, preLoad.size());
                        }
                        if(!tibco.admin.enterpriseAssets.shdResDefs.ServerSSL || !tibco.admin.enterpriseAssets.shdResDefs.ServerSSL.ShdSSLServerResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/ServerSSL/ShdSSLServerResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ServerSSL.ShdSSLServerResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ServerSSL.ShdSSLServerResDefs, preLoad.size());
                        }
                        /* remove SSL client
                        if (!tibco.admin.enterpriseAssets.shdResDefs.ClientSSL || !tibco.admin.enterpriseAssets.shdResDefs.ClientSSL.ShdSSLClientResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/ClientSSL/ShdSSLClientResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ClientSSL.ShdSSLClientResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ClientSSL.ShdSSLClientResDefs, preLoad.size());
                        }*/
                        if(!tibco.admin.enterpriseAssets.shdResDefs.Identity || !tibco.admin.enterpriseAssets.shdResDefs.Identity.ShdIdentityResDefs) {
                            try {
                                tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/Identity/ShdIdentityResDefs.js", this.getNamespace());
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.Identity.ShdIdentityResDefs, preLoad.size());
                            }
                            catch(ex) {
                                tibco.admin.Main.logException(ex);
                            }
                        }
                        else {
                            preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.Identity.ShdIdentityResDefs, preLoad.size());
                        }
                        this.loadPlugins("tibco.admin.enterpriseAssets.shdResDefs.ShdResDefsInterface", preLoad);
                    }
                    else {
                        this.onAfterGetPlugins();
                    }
                }
            }

            plugin.prototype.onAfterComponentUnloaded = function() {
                if(this.isInEditMode()) {
                    this.endEditMode();
                }
                this.envId = null;
                this.nodeId = null;
                this.block = null;
            }

            plugin.prototype.loadDetails = function(objEvent) {
                if(objEvent.status == "SUCCESS") {
                    this.block = objEvent.obj;
                    this.block.getDescendantOfName("btnEdit_34").setEnabled((this.nodeState == "Starting") ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                    var me = this;
                    this.block.handler = me;
                    this.mtx = this.block.getDescendantOfName("mtxShdReso_34");
                    this.recordIds = null;
                    if(this.nodeId) {
                        if(!tibco.admin.enterpriseAssets.shdResDefs.ShdResDefDetails) {
                            tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/ShdResDefDetails.js",
                                    "tibco.admin");
                        }
                        if(this.getPluginList().size() == 0) {
                            var preLoad = new jsx3.util.List(0);

                            // load bundled shared resource definitions
                            // TODO: add RV, SSL
                            if(!tibco.admin.enterpriseAssets.shdResDefs.HTTP || !tibco.admin.enterpriseAssets.shdResDefs.HTTP.ShdHttpResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/HTTP/ShdHttpResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.HTTP.ShdHttpResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.HTTP.ShdHttpResDefs, preLoad.size());
                            }
                            if(!tibco.admin.enterpriseAssets.shdResDefs.JDBC || !tibco.admin.enterpriseAssets.shdResDefs.JDBC.ShdJdbcResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/JDBC/ShdJdbcResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JDBC.ShdJdbcResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JDBC.ShdJdbcResDefs, preLoad.size());
                            }
                            if(!tibco.admin.enterpriseAssets.shdResDefs.EMS || !tibco.admin.enterpriseAssets.shdResDefs.EMS.ShdEmsResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/EMS/ShdEmsResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.EMS.ShdEmsResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.EMS.ShdEmsResDefs, preLoad.size());
                            }
                            if(!tibco.admin.enterpriseAssets.shdResDefs.JNDI || !tibco.admin.enterpriseAssets.shdResDefs.JNDI.ShdJndiResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/JNDI/ShdJndiResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JNDI.ShdJndiResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.JNDI.ShdJndiResDefs, preLoad.size());
                            }
                            if(!tibco.admin.enterpriseAssets.shdResDefs.RV || !tibco.admin.enterpriseAssets.shdResDefs.RV.ShdRVResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/RV/ShdRVResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.RV.ShdRVResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.RV.ShdRVResDefs, preLoad.size());
                            }
                            if(!tibco.admin.enterpriseAssets.shdResDefs.ServerSSL || !tibco.admin.enterpriseAssets.shdResDefs.ServerSSL.ShdSSLServerResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/ServerSSL/ShdSSLServerResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ServerSSL.ShdSSLServerResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ServerSSL.ShdSSLServerResDefs, preLoad.size());
                            }
                            /* remove SSL client
                            if (!tibco.admin.enterpriseAssets.shdResDefs.ClientSSL || !tibco.admin.enterpriseAssets.shdResDefs.ClientSSL.ShdSSLClientResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/ClientSSL/ShdSSLClientResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ClientSSL.ShdSSLClientResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.ClientSSL.ShdSSLClientResDefs, preLoad.size());
                            }*/
                            if(!tibco.admin.enterpriseAssets.shdResDefs.Identity || !tibco.admin.enterpriseAssets.shdResDefs.Identity.ShdIdentityResDefs) {
                                try {
                                    tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/shdResDefs/Identity/ShdIdentityResDefs.js", this.getNamespace());
                                    preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.Identity.ShdIdentityResDefs, preLoad.size());
                                }
                                catch(ex) {
                                    tibco.admin.Main.logException(ex);
                                }
                            }
                            else {
                                preLoad.add(tibco.admin.enterpriseAssets.shdResDefs.Identity.ShdIdentityResDefs, preLoad.size());
                            }
                            this.loadPlugins("tibco.admin.enterpriseAssets.shdResDefs.ShdResDefsInterface", preLoad);
                        }
                        else {
                            this.onAfterGetPlugins();
                        }
                    }
                    this.mtx.getDescendantOfName("mcUse_34").setValueTemplate(tibco.admin.Main.getServer().getDynamicProperty("@@Enabled View Value Template_34"));
                }
                else {
                    if(objEvent.exception) {
                        tibco.admin.Main.logException(objEvent.exception, objEvent.message);
                    }
                    else {
                        jsx3.log(objEvent.message);
                    }
                }
            }

            plugin.prototype.radBtn_onclick = function(id, value) {
                var objCDFDocument = this.mtx.getXML();
                var objRec = objCDFDocument.selectSingleNode("//record[@jsxid='" + id + "']");
                if(objRec) {
                    objRec.setAttribute("isAssociatedToNode", value);
                }
            }

            plugin.prototype.btnEdit_onclick = function() {
                this.beginEditMode();
                this.toggleMode();
                this.toggleInstallBtn();
            }

            plugin.prototype.btnSave_onclick = function() {
                // Create a new document to populate the records which are associated with the Env record.
                var server = tibco.admin.Main.getServer();
                var cdfMtx = this.mtx.getXML();
                var list = cdfMtx.selectNodes("//record[@isAssociatedToNode='true']");
                var cdfList = jsx3.xml.CDF.Document.newDocument();
                var cacheMtxNew = server.getCache().setDocument("cacheShdResoNew_34", cdfList);
                var iter = list.iterator();
                while(iter.hasNext()) {
                    try {
                        var obj = iter.next();
                        cdfList.appendChild(obj.cloneNode(true));
                    }
                    catch (ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                this.callassociateManagedResourcesToNode();
            }

            plugin.prototype.doCancelEdits = function() {
                this.callgetManagedResourceNodeAssociations();
                this.endEditMode();
                this.toggleMode();
            }

            plugin.prototype.getConfirmText = function() {
                return tibco.admin.Main.getServer().getDynamicProperty("@@Confirm Discard Text_34");
            }

            plugin.prototype.btnInstall_onclick = function() {
                var list = this.mtx.getSelectedNodes();
                var cdfList = jsx3.xml.CDF.Document.newDocument();
                var iter = list.iterator();
                while(iter.hasNext()) {
                    try {
                        var obj = iter.next();
                        cdfList.appendChild(obj.cloneNode(true));
                    }
                    catch (ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                var server = tibco.admin.Main.getServer();
                server.getCache().setDocument("cacheInstall_34", cdfList);
                this.callinstallManagedResources();
            }

            plugin.prototype.btnUninstall_onclick = function() {
                var list = this.mtx.getSelectedNodes();
                var cdfList = jsx3.xml.CDF.Document.newDocument();
                var iter = list.iterator();
                while(iter.hasNext()) {
                    try {
                        var obj = iter.next();
                        cdfList.appendChild(obj.cloneNode(true));
                    }
                    catch (ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                var server = tibco.admin.Main.getServer();
                server.getCache().setDocument("cacheUninstall_34", cdfList);
                this.calluninstallManagedResources();
            }

            plugin.prototype.toggleMode = function() {
                var server = tibco.admin.Main.getServer();
                var savecancel = this.isInEditMode() ? jsx3.gui.Block.DISPLAYBLOCK : jsx3.gui.Block.DISPLAYNONE;
                var edit = this.isInEditMode() ? jsx3.gui.Block.DISPLAYNONE : jsx3.gui.Block.DISPLAYBLOCK;
                if(this.isInEditMode()) {
                    this.block.getDescendantOfName("mcUse_34").setValueTemplate(server.getDynamicProperty("@@Enabled Edit Value Template_34"));
					this.block.getDescendantOfName("mcUsage_34").setValueTemplate(server.getDynamicProperty("@@usageDisplay"));
                }
                else {
                    this.block.getDescendantOfName("mcUse_34").setValueTemplate(server.getDynamicProperty("@@Enabled View Value Template_34"));
					this.block.getDescendantOfName("mcUsage_34").setValueTemplate(server.getDynamicProperty(""));
                }
                this.block.getDescendantOfName("btnSave_34").setDisplay(savecancel, true);
                this.block.getDescendantOfName("btnCancel_34").setDisplay(savecancel, true);
                this.block.getDescendantOfName("btnEdit_34").setDisplay(edit, true);
                this.mtx.repaintData();
            }

            plugin.prototype.mtx_onselected = function(arrRecordIds) {
                //To remember which rows have been selected.
                this.recordIds = arrRecordIds;
                this.toggleInstallBtn();
            }

            plugin.prototype.setNodeState = function(state) {
                this.nodeState = state;
                if(this.block) {
                    this.block.getDescendantOfName("btnEdit_34").setEnabled((this.nodeState == "Starting") ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                }
            }

            //If isAssociatedToNode is false, set Install and Uninstall button disabled.
            plugin.prototype.toggleInstallBtn = function () {
                try {
                    if(!this.isInEditMode()) {
                        var list = this.mtx.getSelectedNodes();
                        var flag = true;
                        var count = list.size();
                        var installed = 0
                        var uninstalled = 0
                        var markedForInstall = 0
                        var markedForUninstall = 0
                        var unknown = 0;
                        var nodeRunning = (!this.nodeState || (this.nodeState == "Stop Failed") || (this.nodeState == "Running"));
                        var iter = list.iterator();
                        while(iter.hasNext()) {
                            var node = iter.next();
                            var state = node.getAttribute("actualState");
                            switch(state) {
                                case "Installed":
                                    installed++;
                                    break;
                                case "Uninstalled":
                                    uninstalled++;
                                    break;
                                case "Marked for Install":
                                    markedForInstall++;
                                    break;
                                case "Marked for Uninstall":
                                    markedForUninstall++;
                                    break;
                                case "Unknown":
                                    unknown++;
                                    break;
                                default:
                                    unknown++;
                                    break;
                            }
                            if(node.getAttribute("isAssociatedToNode") == "false" || node.getAttribute("sharedConfigType") == "JNDI" || node.getAttribute("sharedConfigType") == "Identity" || node.getAttribute("sharedConfigType") == "SSL Client" || node.getAttribute("sharedConfigType") == "SSL Server") {
                                flag = false;
                            }
                        }

                        tibco.admin.Main.getServer().getJSXByName("btnInstall_34").setEnabled((nodeRunning && (count > 0) && ((uninstalled + markedForInstall + unknown) == count) && flag) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);
                        tibco.admin.Main.getServer().getJSXByName("btnUninstall_34").setEnabled((nodeRunning && (count > 0) && ((installed + markedForUninstall + unknown) == count) && flag) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);
                    }
                    else {
                        tibco.admin.Main.getServer().getJSXByName("btnInstall_34").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                        tibco.admin.Main.getServer().getJSXByName("btnUninstall_34").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    }
                }
                catch(ex) {
                    jsx3.log(ex);
                    tibco.admin.Main.logException(ex);
                }
            }

            plugin.prototype.reSelectMtx = function() {
                if(this.recordIds && this.recordIds.length > 0) {
                    for(i = 0; i < this.recordIds.length; i++) {
                        this.mtx.selectRecord(this.recordIds[i]);
                    }
                }
                this.mtx.getParent().repaint();
                this.mtx.repaint();
            }
			
			//first invoke the getDesignations and then invoke the getManagedResourceNodeAssociations
            plugin.prototype.callgetManagedResourceNodeAssociations = function() {
				var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/environments/shdReso/rules/getDesignations.xml", "getDesignations", "Get Designations");
				objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagedResourcesEndpointURL());
				objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onCallGetDesignationsSuccess); 
				objService.doCall();
            };

			plugin.prototype.usageCache = null;

			plugin.prototype.onCallGetDesignationsSuccess = function(objEvent){
				this.usageCache = tibco.admin.Main.getServer().getCache().getDocument("cacheUsage_34");
				var objService = tibco.admin.Main.loadService("tibco.admin",
                        "tibco/admin/environments/shdReso/rules/getManagedResourceNodeAssociations.xml",
                        "getManagedResourceNodeAssociations",
                        "Get ManagedResourceNodeAssociations");
                //subscribe and call
				
				this.isSelectedArray = new Array();
				this.dialogSelectedArray = new Array();
                objService.EntityID = this.nodeId;
                var me = this;
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.ongetManagedResourceNodeAssociationsSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.ongetManagedResourceNodeAssociationsError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.ongetManagedResourceNodeAssociationsInvalid);
                objService.setInboundURL("tibco/admin/environments/shdReso/docs/getManagedResourceNodeAssociations.xml");
                if(tibco.admin.Main.getServer().getEnv("MODE")) {
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagedResourcesEndpointURL());
                }
                objService.doCall();
			}
            plugin.prototype.ongetManagedResourceNodeAssociationsSuccess = function(objEvent) {
                this.reSelectMtx();
                this.toggleInstallBtn();
                this.tempCacheDoc = this.mtx.getXML().cloneDocument();
                this.block.getDescendantOfName("selFilterEnable").setValue(tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All"));
            };

            plugin.prototype.ongetManagedResourceNodeAssociationsError = function(objEvent) {
            };

            plugin.prototype.ongetManagedResourceNodeAssociationsInvalid = function(objEvent) {
            };

            plugin.prototype.callassociateManagedResourcesToNode = function() {
                var objService = tibco.admin.Main.loadService("tibco.admin",
                        "tibco/admin/environments/shdReso/rules/associateManagedResourcesToNode.xml",
                        "associateManagedResourcesToNode",
                        "associateManagedResourcesToNode");

                //subscribe and call
                objService.EntityID = this.nodeId;
                var me = this;
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onassociateManagedResourcesToNodeSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.onassociateManagedResourcesToNodeError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.onassociateManagedResourcesToNodeInvalid);
                if(tibco.admin.Main.getServer().getEnv("MODE")) {
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagedResourcesEndpointURL());
                }
                objService.doCall();
            };

            plugin.prototype.onassociateManagedResourcesToNodeSuccess = function(objEvent) {
                this.endEditMode();
                this.toggleMode();
                this.callgetManagedResourceNodeAssociations();
            };

            plugin.prototype.onassociateManagedResourcesToNodeError = function(objEvent) {
            };

            plugin.prototype.onassociateManagedResourcesToNodeInvalid = function(objEvent) {
            };

            plugin.prototype.callinstallManagedResources = function() {
                var objService = tibco.admin.Main.loadService("tibco.admin",
                        "tibco/admin/environments/shdReso/rules/installManagedResources.xml",
                        "installManagedResources",
                        "installManagedResources");

                //subscribe and call
                var me = this;
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.oninstallManagedResourcesSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.oninstallManagedResourcesError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.oninstallManagedResourcesInvalid);
                if(tibco.admin.Main.getServer().getEnv("MODE")) {
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagedResourcesEndpointURL());
                }
                objService.doCall();
            };

            plugin.prototype.oninstallManagedResourcesSuccess = function(objEvent) {
                this.callgetManagedResourceNodeAssociations();
            };

            plugin.prototype.oninstallManagedResourcesError = function(objEvent) {
            };

            plugin.prototype.oninstallManagedResourcesInvalid = function(objEvent) {
            };

            plugin.prototype.calluninstallManagedResources = function() {
                var objService = tibco.admin.Main.loadService("tibco.admin",
                        "tibco/admin/environments/shdReso/rules/uninstallManagedResources.xml",
                        "uninstallManagedResources",
                        "uninstallManagedResources");

                //subscribe and call
                var me = this;
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onuninstallManagedResourcesSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.onuninstallManagedResourcesError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.onuninstallManagedResourcesInvalid);
                if(tibco.admin.Main.getServer().getEnv("MODE")) {
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagedResourcesEndpointURL());
                }
                objService.doCall();
            };

            plugin.prototype.onuninstallManagedResourcesSuccess = function(objEvent) {
                this.callgetManagedResourceNodeAssociations();
            };

            plugin.prototype.onuninstallManagedResourcesError = function(objEvent) {
            };

            plugin.prototype.onuninstallManagedResourcesInvalid = function(objEvent) {
            };

            plugin.prototype.filterResults = function() {
                if(this.tempCacheDoc) {
                    var tempCacheDoc = this.tempCacheDoc;
                    var filterEnable = this.block.getDescendantOfName("selFilterEnable").getText();

                    if(filterEnable == tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All")) {
                        filterEnable = "All";
                    }
                    if(filterEnable == tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All Enabled")) {
                        filterEnable = "true";
                    }
                    if(filterEnable == tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All Not Enabled")) {
                        filterEnable = "false";
                    }

                    this.mtx.setXMLTransformers(tibco.admin.Main.resolveURI("tibco.admin", "tibco/admin/environments/shdReso/xsl/transform.xsl"));
                    this.mtx.setXSLParam("enable", filterEnable);
                    this.mtx.setSourceXML(tempCacheDoc);
                    this.mtx.repaintData();
                }
            }

            plugin.prototype.getComponentPath = function() {
                return "tibco/admin/environments/shdReso/component.xml"
            }

            plugin.prototype.buttonSelected = function() {
                if(!this.isInEditMode()) {
                    this.callgetManagedResourceNodeAssociations();
                }
            }

			plugin.prototype.selectId = null;
			plugin.prototype.isSelectedArray = new Array();
			plugin.prototype.dialogSelectedArray = new Array();

			plugin.prototype.callSelectUseage = function(selectId) {
				var server = tibco.admin.Main.getServer();
				this.selectId = selectId;
				this.dialog = tibco.admin.Main.loadUIResource(tibco.admin.Main.getServer().getBodyBlock(), "tibco.admin", "tibco/admin/environments/shdReso/ui/shdUsageSelect.xml", true);
				this.dialog.getFirstChildOfType("jsx3.gui.WindowBar").setText(server.getDynamicProperty("@@usageSelectText_34"),true);
				this.dialog.parent = this;

				tibco.admin.Main.getServer().getCache().clearById(this.dialog.getDescendantOfName("mtxUsage_34").getXMLId());
				this.dialog.getDescendantOfName("mtxUsage_34").setXMLString(this.usageCache);
				this.dialog.getDescendantOfName("mtxUsage_34").repaint();

				tibco.admin.Main.getServer().getJSXByName("mtxUsage_34").repaint();
				var nodes = this.usageCache.getChildNodes();
				var disabledCheckArray = this.isSelectedArray.clone();
				var isCheckedArray = new Array();
				var objShdReso = this.block.getDescendantOfName("mtxShdReso_34").getXML();
				var selectRecord = objShdReso.selectSingleNode("//record[@jsxid=" + this.selectId + "]");
				if(selectRecord){
					var selectDesignations = selectRecord.getAttribute("designation");
					if(selectDesignations != null && selectDesignations != "" && selectDesignations != undefined){
						var selectDesignation = selectDesignations.split(",");
						for(var i = 0 ; i < selectDesignation.length ; i++){
							for(var n = 0 ; n < nodes.size() ; n++) {
								var node = nodes.get(n);
								if(node && node.getAttribute("displayName") == selectDesignation[i]) {
									for(var j = 0 ; j < disabledCheckArray.length ; j++){
										if(node.getAttribute("code") == disabledCheckArray[j]){
											disabledCheckArray.splice(j,1);
											isCheckedArray[isCheckedArray.length] = node.getAttribute("code");
										}
									}
								}
							}
						}
					}
				}
				var mtxUsageObjHTML = server.getJSXByName("mtxUsage_34").getRendered();
				for(var i = 0 ; i < nodes.size() ; i++) {
					var node = nodes.get(i);
					if(node) {
						var inputGIobj = jsx3.html.getJSXParent(mtxUsageObjHTML.getElementsByTagName("INPUT")[i]);
						var resourceFunObj = jsx3.html.getJSXParent(mtxUsageObjHTML.getElementsByTagName("DIV")[6]);
						mtxUsageObjHTML.getElementsByTagName("INPUT")[i].setAttribute("code",node.getAttribute("code"));
						for(var j = 0 ; j < disabledCheckArray.length ; j++){
							if(node.getAttribute("code") == disabledCheckArray[j]) {
								inputGIobj.setEnabled(jsx3.gui.Form.STATEDISABLED);
								inputGIobj.setDisabledColor("#ADB2B4");
                        		inputGIobj.setTip(tibco.admin.Main.getServer().getDynamicProperty("@@checkBoxToolTip_34"));
								mtxUsageObjHTML.getElementsByTagName("INPUT")[i].setAttribute("disabled","true");
								
								resourceFunObj.setEnabled(jsx3.gui.Form.STATEDISABLED);
								resourceFunObj.setDisabledColor("#ADB2B4");
								mtxUsageObjHTML.getElementsByTagName("DIV")[6].setAttribute("disabled","true");
							}
						}
						for(var k = 0 ; k < isCheckedArray.length ; k++){
							if(node.getAttribute("code") == isCheckedArray[k]) {
								inputGIobj.setChecked(1);
								mtxUsageObjHTML.getElementsByTagName("INPUT")[i].setAttribute("checked","true");
							}
						}
					}
				}
			}

			plugin.prototype.onApplySelected = function(applyObj,objEvent) {
				this.dialogSelectedArray = new Array();
				var selectCheckedCode = "";
				var selectCheckedDisplayName = "";

				var server = tibco.admin.Main.getServer();
				var objCDFWSAdress = server.getCache().getDocument(server.getJSXByName("mtxUsage_34").getXMLId());
				var mtxUsageObjHTML = server.getJSXByName("mtxUsage_34").getRendered();
				
				var nodes = objCDFWSAdress.getChildNodes();
				for(var i = 0 ; i < nodes.size() ; i++) {
					var node = nodes.get(i);
					if(node && (node.getAttribute("checked") == 1)) {
						selectCheckedDisplayName += node.getAttribute("displayName") + ",";
						selectCheckedCode += node.getAttribute("code") + ",";
						this.dialogSelectedArray[this.dialogSelectedArray.length] = node.getAttribute("code");
					}
				}

				var objShdReso = this.block.getDescendantOfName("mtxShdReso_34").getXML();
				var selectRecord = objShdReso.selectSingleNode("//record[@jsxid=" + this.selectId + "]");
				if(selectRecord){
					selectRecord.setAttribute("selectDisplayNameString",selectCheckedDisplayName.substring(0,selectCheckedDisplayName.length -1));
					selectRecord.setAttribute("selectCodeString",selectCheckedCode.substring(0,selectCheckedCode.length -1));
					selectRecord.setAttribute("designation",selectCheckedDisplayName.substring(0,selectCheckedDisplayName.length -1));
					selectRecord.setAttribute("designationSave",selectCheckedCode.substring(0,selectCheckedCode.length -1));
				}
				this.selectId = "";
				this.isSelectedArray = this.dialogSelectedArray.clone();
				this.block.getDescendantOfName("mtxShdReso_34").repaint();
				applyObj.getAncestorOfType(jsx3.gui.Dialog).doClose();
			}

			plugin.prototype.onDialogClosed = function(closeObj,objEvent) {
				this.dialogSelectedArray = this.isSelectedArray.clone();
				closeObj.getAncestorOfType(jsx3.gui.Dialog).doClose();
			}

			plugin.prototype.getDisplayDesignation = function(designationValue,objRecord) {
				var code = designationValue;
				if(designationValue != "" && designationValue != null && designationValue != undefined){
					for(var j = 0 ; j < this.isSelectedArray.length ; j++){
						if(this.isSelectedArray[j] == designationValue){
							this.isSelectedArray.splice(j,1);
						}
					}
					this.isSelectedArray[this.isSelectedArray.length] = designationValue;
					this.dialogSelectedArray[this.dialogSelectedArray.length] = designationValue;
					var nodes = this.usageCache.getChildNodes();
					for(var i = 0 ; i < nodes.size() ; i++) {
						var node = nodes.get(i);
						if(node && node.getAttribute("code") == designationValue) {
							designationValue = node.getAttribute("displayName");
						}
					}
				}
				var returnValue = objRecord.getAttribute("designation");
				if(objRecord.getAttribute("designation") != null && objRecord.getAttribute("designation") != "" && objRecord.getAttribute("designation") != undefined){
					returnValue += "," + designationValue;
				}else{
					returnValue = designationValue;
				}
				objRecord.setAttribute("designationSave",code);
				return returnValue;
            }

			plugin.prototype.onCheckBoxClick = function(thisObj,objEVENT,intCHECKED) {return;
				var operateDispalyName = objEVENT.srcElement().getAttribute("code");
				if(intCHECKED == 1){
					for(var i = 0 ; i < this.dialogSelectedArray.length ; i++){
						if(operateDispalyName == this.dialogSelectedArray[i]){
							this.dialogSelectedArray.splice(i,1);
						}
					}
					this.dialogSelectedArray[this.dialogSelectedArray.length] = operateDispalyName;
				}else if(intCHECKED == 0){
					for(var i = 0 ; i < this.dialogSelectedArray.length ; i++){
						if(operateDispalyName == this.dialogSelectedArray[i]){
							this.dialogSelectedArray.splice(i,1);
						}
					}
				}
            }
        }
        );